home *** CD-ROM | disk | FTP | other *** search
- package hhapplet;
-
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Dimension;
- import java.awt.Font;
- import java.awt.FontMetrics;
- import java.awt.Graphics;
- import java.awt.Rectangle;
- import java.awt.image.ImageObserver;
-
- public class TabButton extends CanvasButton {
- protected String label;
- protected int x_offset = -1;
- protected int y_offset = -1;
- protected Font active;
- protected Font inactive;
- protected int tab_x;
- protected int tab_y;
- protected int tab_width;
- protected int tab_height;
- protected boolean m_bDrawLeft = true;
- protected boolean m_bDrawRight = true;
- protected boolean m_bCenterBroken = false;
-
- protected void centerText(Font var1) {
- Rectangle var2 = ((Component)this).bounds();
- FontMetrics var3 = ((Component)this).getFontMetrics(var1);
- int var4 = var3.stringWidth(this.label);
- int var5 = var3.getMaxAscent();
- this.y_offset = var2.height - var5;
- this.y_offset = this.y_offset / 2 + var5;
- this.x_offset = var2.width - var4;
- this.x_offset /= 2;
- if (this.m_bCenterBroken && !((Component)this).isEnabled()) {
- this.x_offset += 3;
- }
-
- }
-
- public void reshape(int var1, int var2, int var3, int var4) {
- super.reshape(var1, var2, var3, var4);
- this.tab_x = var1;
- this.tab_y = var2;
- this.tab_width = var3;
- this.tab_height = var4;
- this.centerText(((Component)this).getFont());
- }
-
- public TabButton(String var1) {
- int var2 = WebHelp.GetFontSize();
-
- for(this.active = new Font(WebHelp.GetFontName(), 1, var2); this.active.getSize() != var2 && var2 < WebHelp.GetFontSize() + 10; this.active = new Font(WebHelp.GetFontName(), 1, var2)) {
- ++var2;
- }
-
- this.inactive = new Font(WebHelp.GetFontName(), 0, var2);
- ((Component)this).setFont(this.inactive);
- this.label = var1;
- if (System.getProperty("java.vendor").startsWith("Netscape") && System.getProperty("os.name").startsWith("Windows 95")) {
- try {
- String var3 = System.getProperty("java.version");
- if (var3.startsWith("1.02")) {
- this.m_bCenterBroken = true;
- }
-
- Integer var4 = new Integer(var3.substring(0, 1));
- Integer var5 = new Integer(var3.substring(2, 3));
- Integer var6 = new Integer(var3.substring(4, 5));
- if (var4 <= 1 && var5 <= 1 && var6 <= 2) {
- this.m_bCenterBroken = true;
- return;
- }
- } catch (Exception var7) {
- }
- }
-
- }
-
- public void paint(Graphics var1) {
- var1.setColor(((Component)this).getBackground());
- var1.fillRect(0, 0, ((Component)this).bounds().width, ((Component)this).bounds().height);
- if (super.img != null) {
- var1.drawImage(super.img, 2, 2, (ImageObserver)null);
- } else if (this.label != null) {
- this.centerText(((Component)this).getFont());
- var1.setColor(((Component)this).getForeground());
- var1.setFont(((Component)this).getFont());
- var1.drawString(this.label, this.x_offset, this.y_offset);
- }
-
- this.paintBorderOut(var1);
- }
-
- public void paintBorderOut(Graphics var1) {
- Rectangle var2 = ((Component)this).bounds();
- if (!((Component)this).isEnabled()) {
- var1.setColor(Color.white);
- var1.drawLine(2, 0, var2.width - 3, 0);
- var1.drawLine(1, 1, 1, 1);
- var1.drawLine(0, 2, 0, var2.height - 1);
- var1.setColor(Color.white);
- var1.drawLine(2, 0, var2.width - 3, 0);
- } else if (this.m_bDrawLeft) {
- var1.setColor(Color.white);
- var1.drawLine(2, 3, var2.width - 3, 3);
- var1.drawLine(1, 4, 1, 4);
- var1.drawLine(0, 5, 0, var2.height - 1);
- } else {
- var1.setColor(Color.white);
- var1.drawLine(0, 3, var2.width - 3, 3);
- }
-
- if (!((Component)this).isEnabled()) {
- var1.setColor(Color.darkGray);
- var1.drawLine(var2.width - 2, 2, var2.width - 2, var2.height - 1);
- var1.setColor(Color.black);
- var1.drawLine(var2.width - 2, 1, var2.width - 2, 1);
- var1.drawLine(var2.width - 1, 2, var2.width - 1, var2.height - 1);
- } else if (this.m_bDrawRight) {
- var1.setColor(Color.darkGray);
- var1.drawLine(var2.width - 2, 5, var2.width - 2, var2.height - 1);
- var1.setColor(Color.black);
- var1.drawLine(var2.width - 2, 4, var2.width - 2, 4);
- var1.drawLine(var2.width - 1, 5, var2.width - 1, var2.height - 1);
- } else {
- var1.setColor(Color.white);
- var1.drawLine(2, 3, var2.width - 1, 3);
- }
-
- if (((Component)this).isEnabled()) {
- var1.setColor(Color.white);
- var1.drawLine(0, var2.height - 1, var2.width - 1, var2.height - 1);
- var1.setColor(((Component)this).getBackground());
- var1.drawLine(0, 0, var2.width - 1, 0);
- var1.drawLine(0, 1, var2.width - 1, 1);
- var1.drawLine(0, 2, var2.width - 1, 2);
- }
-
- }
-
- public void disable() {
- if (((Component)this).isEnabled()) {
- ((Component)this).setFont(this.active);
- super.reshape(this.tab_x, this.tab_y, this.tab_width, this.tab_height);
- this.centerText(this.active);
- ((Component)this).repaint();
- super.disable();
- }
-
- }
-
- public void enable() {
- if (!((Component)this).isEnabled()) {
- ((Component)this).setFont(this.inactive);
- super.reshape(this.tab_x, this.tab_y, this.tab_width, this.tab_height);
- this.centerText(this.inactive);
- ((Component)this).repaint();
- super.enable();
- }
-
- }
-
- public void enable(boolean var1) {
- if (var1) {
- this.enable();
- } else {
- this.disable();
- }
- }
-
- public void SetDrawRight(boolean var1) {
- this.m_bDrawRight = var1;
- ((Component)this).repaint();
- }
-
- public Dimension preferredSize() {
- try {
- if (super.img != null) {
- return new Dimension(super.img.getWidth(this) + 4, super.img.getHeight(this) + 4);
- } else if (this.label != null) {
- FontMetrics var1 = ((Component)this).getFontMetrics(((Component)this).getFont());
- int var2 = var1.stringWidth(this.label);
- int var3 = var1.getMaxAscent();
- var2 += 20;
- var3 += 8 + var1.getMaxDescent();
- return new Dimension(var2, var3);
- } else {
- return new Dimension(20, 20);
- }
- } catch (Exception var4) {
- return new Dimension(20, 20);
- }
- }
-
- public void SetDrawLeft(boolean var1) {
- this.m_bDrawLeft = var1;
- ((Component)this).repaint();
- }
- }
-